package com.example.test01;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTabHost;

import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Environment;
import android.os.PersistableBundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.security.Permissions;

public class MainActivity extends AppCompatActivity {
    public  String ACCOUNT ="accout";
    public  String PASSWORD ="password";
    private Button btn;
    EditText et1;
    EditText et2;
    private static String[]PERMISSIONS ={
            Manifest.permission.READ_EXTERNAL_STORAGE,
            Manifest.permission.WRITE_EXTERNAL_STORAGE
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.denglu);
        btn = (Button) findViewById(R.id.tv_login);
        et1 = (EditText) findViewById(R.id.name);
        et2 = (EditText) findViewById(R.id.hah);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String account = et1.getText().toString();
                String password = et2.getText().toString();
                Log.d("minafang", "butto onclick");
                String name = et1.getText().toString();
                Log.d("minafang", "edit content:" + name);
                if (name.equalsIgnoreCase("123456789")) {
                    Toast.makeText(MainActivity.this, "it is ok!", Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(MainActivity.this, "input error", Toast.LENGTH_SHORT).show();
                }
                Intent intent = new Intent("com.layout.denglu");
                startActivity(intent);

            }
        });
        checkPermission();



        private void checkPermission(){
            int permission = ActivityCompat.checkSelfPermission(this,
                    Manifest.permission.WRITE_EXTERNAL_STORAGE);
            if (permission!= PackageManager.PERMISSION_GRANTED){
                ActivityCompat.requestPermissions(this,PERMISSIONS,1);
            }

        }





    }


    @Override
    public void onCreate(@Nullable Bundle savedInstanceState, @Nullable PersistableBundle persistentState) {
        super.onCreate(savedInstanceState, persistentState);
        setContentView(R.layout.denglu);
        TextView tv = (TextView) findViewById(R.id.hah);
        File root = Environment.getExternalStorageDirectory();
        if (root.exists()&& root.canWrite()){
            File file =new File(root,"DemoFile.png");
            try{
                if (file.createNewFile()){
                    tv.setText(file.getName()+"创建成功！");
                }
            }else{
                tv.setText(file.getName()+"创建失败");
            }
        }catch(IOException e){
            e.printStackTrace();

        }else{
            tv.setText();
        }


        }



    }










